package cn.wildfire.chat.app.extendsion.classes;

import android.content.Context;

import org.json.JSONObject;

import java.util.HashMap;

import cn.wildfire.chat.app.extendsion.https.OkHttpRequest;
import cn.wildfire.chat.app.extendsion.https.ReqCallBack;
import cn.wildfire.chat.app.extendsion.https.ServerUrlClient;

/**
*  Create by HEKE, 2019/10/16 17:58
*  TODO 查询用户中心账号与安全检测设置
*/
public class AccountSecurityCheckRequest {

    private Context context;
    private String userId;

    private OnAccountSecurityCheckListener onAccountSecurityCheckListener;

    public AccountSecurityCheckRequest(Context context,String userId,OnAccountSecurityCheckListener onAccountSecurityCheckListener) {
        this.context = context;
        this.userId = userId;
        this.onAccountSecurityCheckListener = onAccountSecurityCheckListener;
        req();
    }

    protected void req(){
        try {
            HashMap<String,Object> params = new HashMap<>();
            params.put("uid",userId);
            OkHttpRequest.getNewInstance(context).requestAsynJsonObject(ServerUrlClient.ACCOUNT_SECURITY_CENTER, params, new ReqCallBack<String>() {
                @Override
                public void onReqSuccess(String result) {
                    try {
                        ResponseEntity<JSONObject, SecurityStatus> responseEntity = new ResponseEntity<>(result,SecurityStatus.class);
                        if(responseEntity.isSuccess()){
                            SecurityStatus securityStatus = responseEntity.parseResult();
                            if(onAccountSecurityCheckListener!=null){
                                onAccountSecurityCheckListener.result(securityStatus);
                            }
                        }else {
                            if(onAccountSecurityCheckListener!=null){
                                onAccountSecurityCheckListener.result(null);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onReqFailed(String errorMsg) {
                    if(onAccountSecurityCheckListener!=null){
                        onAccountSecurityCheckListener.result(null);
                    }
                }
            }).request();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public interface OnAccountSecurityCheckListener{
        void result(SecurityStatus securityStatus);
    }

}
